package cn.doit.scala.day03

/**
 * @DATE 2021/12/27/14:42
 * @Author MDK
 * @Version 2021.2.2
 *
 * 用arr和用list存储数据的区别
 * */
object C07_GroupBy {
  def main(args: Array[String]): Unit = {
    val arr = Array[Int](1, 2, 3, 4, 5, 6, 7, 8)
    val map1: Map[Int, Array[Int]] = arr.groupBy(e => e)
    map1.foreach(tp=>println(tp._1,tp._2.toList))
//    println(map1.toList)
    val map2: Map[Boolean, Array[Int]] = arr.groupBy(e => e % 2 == 0)
    map2.foreach(tp=>println(tp._1,tp._2.toList))

    println("----------------------------------------------------")
    val list = List[Int](1, 2, 3, 4, 5, 6, 7, 8)
    val mp1 = list.groupBy(e => e)
    mp1.foreach(tp=>println(tp._1,tp._2))
    val mp2: Map[Boolean, List[Int]] = list.groupBy(e => e % 2 == 0)
    mp2.foreach(tp=>println(tp._1,tp._2))
  }
}
